﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;

namespace SqliteManager.SQLite3
{
    public static class Sqlite3DataBaseExtension
    {
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="db"></param>
        /// <param name="table"></param>
        /// <param name="obj"></param>
        /// <param name="serilizeList"></param>
        public static void InsertData( this Sqlite3DataBase db, string table, object obj, Stack<string> serilizeList)
        {
            string sql = $"INSERT INTO '{table}' {DataBaseWriter.GetInsertSQL(obj, serilizeList)};";
            db.ExecuteQuery(sql);
        }

        /// <summary>
        /// 读取对象（依赖于Extensions）
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="table"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static T ReadObject<T>(this Sqlite3DataBase db, string table, string condition) where T : new()
        {
            string sql = $"SELECT * FROM '{table}' WHERE {condition};";
            return DataBaseReader.Read<T>(db.ExecuteQuery(sql));
        }
    }
}
